# Read in the data:
oilspill <- read_sf(here("oil_spill_data"),
                    layer = "Oil_Spill_Incident_Tracking_%5Bds394%5D") %>% 
  clean_names() %>% 
  mutate(date = as.Date(dateofinci)) %>% 
  mutate(date = ymd(date)) %>% 
  rename(name = localecoun) %>% 
  select(name, date, inlandmari)

counties <- read_sf(here("ca_counties"),
                    layer = "CA_Counties_TIGER2016") %>% 
  clean_names() %>% 
  select(name)

# Check projection
st_crs(oilspill) # 4326
## Coordinate Reference System:
##   User input: WGS 84 / Pseudo-Mercator 
##   wkt:
## PROJCRS["WGS 84 / Pseudo-Mercator",
##     BASEGEOGCRS["WGS 84",
##         DATUM["World Geodetic System 1984",
##             ELLIPSOID["WGS 84",6378137,298.257223563,
##                 LENGTHUNIT["metre",1]]],
##         PRIMEM["Greenwich",0,
##             ANGLEUNIT["degree",0.0174532925199433]],
##         ID["EPSG",4326]],
##     CONVERSION["Popular Visualisation Pseudo-Mercator",
##         METHOD["Popular Visualisation Pseudo Mercator",
##             ID["EPSG",1024]],
##         PARAMETER["Latitude of natural origin",0,
##             ANGLEUNIT["degree",0.0174532925199433],
##             ID["EPSG",8801]],
##         PARAMETER["Longitude of natural origin",0,
##             ANGLEUNIT["degree",0.0174532925199433],
##             ID["EPSG",8802]],
##         PARAMETER["False easting",0,
##             LENGTHUNIT["metre",1],
##             ID["EPSG",8806]],
##         PARAMETER["False northing",0,
##             LENGTHUNIT["metre",1],
##             ID["EPSG",8807]]],
##     CS[Cartesian,2],
##         AXIS["easting (X)",east,
##             ORDER[1],
##             LENGTHUNIT["metre",1]],
##         AXIS["northing (Y)",north,
##             ORDER[2],
##             LENGTHUNIT["metre",1]],
##     USAGE[
##         SCOPE["unknown"],
##         AREA["World - 85°S to 85°N"],
##         BBOX[-85.06,-180,85.06,180]],
##     ID["EPSG",3857]]
# Set Counties CRS
counties <- st_transform(counties, st_crs(oilspill))



tmap_mode("view")

tm_shape(counties)+
  tm_polygons(alpha = 0.4)+
  tm_shape(oilspill)+
  tm_dots(col = "red", scale = .8, alpha = 0.6)+
  tm_basemap("Esri.WorldTopoMap")
#Need to do the join

ggplot()+
  geom_sf(data = counties)+
  geom_sf(data = oilspill, alpha = 0.5)+
  theme_void()